package com.weixing.mall.provider.controller.front;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoNeedAccess;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.mapper.AppVersionMapper;
import com.weixing.mall.provider.model.domain.AppVersion;
import com.weixing.mall.provider.model.enums.cms.DeviceEunm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * App版本接口
 *
 * @author siashan
 * @since v1
 */
@RestController
@RequestMapping("front/appversion")
public class FrontAppVersionController extends BaseController {
    @Autowired
    private AppVersionMapper appVersionMapper;

    /**
     * 加载最新的版本
     * @param appType app类型
     * @param device  设备
     * @return APP版本
     */
    @GetMapping("getLatest/{appType}/{device}")
    @NoNeedAccess
    public Result<AppVersion> getLatest(@PathVariable Integer appType,@PathVariable Integer device) {
        AppVersion appVersion = appVersionMapper.getLatest(appType, device);
        if (null != appVersion){
            if (DeviceEunm.ANDROID.getValue().equals(appVersion.getDevice())){
                appVersion.setDownloadUrl("http://lmpic.weixingshishang.cn/" + appVersion.getDownloadUrl());
            }
        }

        return ResultUtil.success(appVersion);
    }
}
